package com.heaboy.collection;

import java.util.LinkedList;
import java.util.Queue;

public class QueueExample {
    public static void main(String[] args) {
        Mystack mystack=new Mystack();
        mystack.push(1);
        mystack.push(2);
        mystack.push(3);
        int sum= mystack.push(4);
        for(int i=0;i<sum;i++){
            System.out.print(mystack.top1());
            mystack.pop1();
        }
    }

}
class Mystack{
    Queue<Integer> queue=new LinkedList<>();
    Queue<Integer> queue1=new LinkedList<>();

    //入栈的次数
    int sum=0;
    //入栈
    public int push(int x){
        queue1.offer(x);
        while(!queue.isEmpty()){
            queue1.offer(queue.poll());
        }
        Queue<Integer> temp=queue;
        queue=queue1;
        queue1=temp;
        sum++;
        return sum;
    }
    // 出栈操作
    public int pop1() {
        return queue.poll();
    }

    // 获取栈顶元素
    public int top1() {
        return queue.peek();
    }

}
